//
//  IComMediator+ApplicationActions.m
//  ICome
//
//  Created by zhangrongwu on 16/10/9.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "IComMediator+ApplicationActions.h"

@implementation IComMediator (ApplicationActions)
//模块的常量
// action 类名 Work 模块统一用Work
NSString * const kIComMediatorTargetApplication = @"Application";
// 类对应方法名
NSString * const kIComNativeFetchApplicationViewController = @"nativeFetchApplicationViewController";
// 扫码
NSString * const kIComNativeFetchRCodeViewController = @"nativeFetchRCodeViewController";
// web page
NSString * const kIComNativeFetchWebViewController = @"nativeFetchWebViewController";

NSString * const kIComNativeFetchGtasksViewController = @"nativeFetchGtasksViewController";


- (UIViewController *)IComMediator_ApplicationViewController {
    return [self IComMediator_ApplicationViewController:nil];
}

- (UIViewController *)IComMediator_ApplicationViewController:(NSDictionary *)params {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetApplication
                                                    action:kIComNativeFetchApplicationViewController
                                                    params:params];
    if ([viewController isKindOfClass:[UIViewController class]]) {
        // view controller 交付出去之后，可以由外界选择是push还是present
        return viewController;
    } else {
        // 这里处理异常场景，具体如何处理取决于产品
        return [[UIViewController alloc] init];
    }
}

- (UIViewController *)IComMediator_WebViewController:(NSDictionary *)params {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetApplication
                                                    action:kIComNativeFetchWebViewController
                                                    params:params];
    if ([viewController isKindOfClass:[UIViewController class]]) {
        return viewController;
    } else {
        return [[UIViewController alloc] init];
    }
}

- (UIViewController *)IComMediator_GtasksViewController:(NSDictionary *)params {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetApplication
                                                    action:kIComNativeFetchGtasksViewController
                                                    params:params];
    if ([viewController isKindOfClass:[UIViewController class]]) {
        return viewController;
    } else {
        return [[UIViewController alloc] init];
    }
}


- (UIViewController *)IComMediator_RCodeViewController:(NSDictionary *)params handler:(IComMediatorObjectHandler)handler {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetApplication
                                                    action:kIComNativeFetchRCodeViewController
                                                    params:params
                                                completion:^(id result) {
                                                    if (handler) {
                                                        handler(result);
                                                    }
                                                }];
    if ([viewController isKindOfClass:[UIViewController class]]) {
        return viewController;
    } else {
        return [[UIViewController alloc] init];
    }
}

@end
